package com.wanxi.servlet.company;

import com.alibaba.fastjson.JSONObject;
import com.wanxi.dto.ResultDTO;
import com.wanxi.vo.CompanyVO;
import com.wanxi.service.CompanyService;
import com.wanxi.service.impl.CompanyServiceImpl;
import com.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/back/company/all")
public class CompanyFindAllServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        1.乱码
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
//        2.得到前端的值
        String startId = req.getParameter("startId");
        String page = req.getParameter("page");
        String limit = req.getParameter("limit");
        String endId = req.getParameter("endId");
        String phone = req.getParameter("phone");
        String net = req.getParameter("net");
        String email = req.getParameter("email");
        String start_create_time = req.getParameter("start_create_time");
        String end_create_time = req.getParameter("end_create_time");


//        3.封装vo
        CompanyVO companyVO = new CompanyVO();
        companyVO.setStartId(Tool.strToInt(startId));
        companyVO.setEndId(Tool.strToInt(endId));
        companyVO.setStartCreateTime(start_create_time);
        companyVO.setEndCreateTime(end_create_time);
        companyVO.setPage(Tool.strToPage(page));
        companyVO.setLimit(Tool.strToLimit(limit));
        companyVO.setPhone(phone);
//       4.调用service
        CompanyService companyService = new CompanyServiceImpl();
//        5.得到返回值
        ResultDTO resultDTO = companyService.findAll(companyVO);

//        6.响应给前端
        resp.getWriter().println(JSONObject.toJSONString(resultDTO));
    }
}
